package com.simple.crawler.core;

import com.simple.crawler.constant.CrawlerStatus;
import com.simple.crawler.utils.StringUtils;

public class Crawler {

    private CrawlerStatus status = CrawlerStatus.READY;

    private String id = StringUtils.getId();

    private CrawlerCache cache = new CrawlerCache();

    private String url;

    private Class<? extends Task>[] taskList;

    public Crawler() {
    }

    public Crawler(String url, Class<? extends Task>... taskList) {
        this.url = url;
        this.taskList = taskList;
    }

    public String getId() {
        return id;
    }

    public CrawlerCache getCache() {
        return cache;
    }

    public String getUrl() {
        return url;
    }

    public Class<? extends Task>[] getTaskList() {
        return taskList;
    }

    public CrawlerStatus getStatus() {
        return status;
    }

    public void setStatus(CrawlerStatus status) {
        this.status = status;
    }

    public boolean isValidate() {
        if (!CrawlerStatus.READY.equals(status)) {
            return false;
        }
        if (StringUtils.isBlank(url)) {
            return false;
        }
        if (taskList == null || taskList.length == 0) {
            return false;
        }
        return true;
    }

}
